<template>
  <view class="setting-container" :style="{height: `${windowHeight}px`}">
    <view class="menu-list">
      <view class="list-cell list-cell-arrow" @click="handleToPwd">
        <view class="menu-item-box">
          <view class="iconfont icon-password menu-icon"></view>
          <view>修改密码</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleToUpgrade">
        <view class="menu-item-box">
          <view class="iconfont icon-refresh menu-icon"></view>
          <view>检查更新</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleCleanTmp">
        <view class="menu-item-box">
          <view class="iconfont icon-clean menu-icon"></view>
          <view>清理缓存</view>
        </view>
      </view>
    </view>
    <view class="cu-list menu">
      <view class="cu-item item-box">
        <view class="content text-center" @click="handleLogout">
          <text class="text-black">退出登录</text>
        </view>
      </view>
    </view>
  </view>
  <view>
    <uni-popup ref="popup" type="dialog">
      <uni-popup-dialog type="info" cancelText="关闭" confirmText="退出"
                        title="通知" content="确定注销并退出系统吗"
                        @confirm="dialogConfirm"
                        @close="dialogClose">
      </uni-popup-dialog>
    </uni-popup>
  </view>
</template>

<script setup>
import {getCurrentInstance, ref} from "vue";
import useUserStore from '@/store/modules/user'
import app_upgrade from "@/uni_modules/app-upgrade/js_sdk";
import {getValidVersion} from "@/api/wms/version";

const {proxy} = getCurrentInstance()

const windowHeight = ref(uni.getSystemInfoSync().windowHeight);
const popup = ref(null);

function handleToPwd() {
  uni.navigateTo({
    url: '/pages_mine/pages/pwd/index'
  });
};

function handleToUpgrade() {

  // #ifdef APP-PLUS
  app_upgrade(async (wgtinfo) => {
    //查询是否更新
    await proxy?.$modal.confirm(`当前版本${wgtinfo.version}, 是否检查更新？`)
    const res = await getValidVersion(wgtinfo.name)
    console.log(res)
    if (res.code == 200) {
      const status = res.data.versionCode == wgtinfo.versionCode ? 0 : 1
      if (status == 0) {
        proxy.$modal.msg('当前已是最新版本');
      }
      return {
        changelog: res.data.remark,
        status, // 0 无新版本 | 1 有新版本
        path: res.data.ossVoList[0].url // 新apk地址
      }
    }
  }, 1)
  // #endif
  // #ifdef H5
  proxy?.$modal.alert('刷新网页将自动更新到最新版');
  // #endif

};

function handleCleanTmp() {
  uni.showToast({
    title: '模块建设中~',
    mask: false,
    icon: "none",
    duration: 1000
  });
};

function handleLogout() {
  popup.value.open();
};

function dialogConfirm() {
  //console.log('----------------点击确认------------')
  useUserStore().logOut().then(() => {
    uni.reLaunch({
      url: '/pages/login'
    });
  })
};

function dialogClose() {
  //console.log('点击关闭')
};
</script>

<style lang="scss" scoped>
.page {
  background-color: #f8f8f8;
}

.item-box {
  background-color: #FFFFFF;
  margin: 30rpx;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  padding: 10rpx;
  border-radius: 8rpx;
  color: #303133;
  font-size: 32rpx;
}
</style>
